package com.spark.searchapi.entity;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.DateFormat;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @author fuqiang
 * @Description 书本商品
 * @Date 2021-03-04
 * 更多注解详细说明参考官网:https://docs.spring.io/spring-data/elasticsearch/docs/4.0.1.RELEASE/reference/html/#elasticsearch.mapping.meta-model
 * 一定要习惯从官网获取信息
 * @Document指定当前类是索引对象。indexName:索引名称;shards:创建索引时的分片数;replicas:创建索引时的备份数
 */
@Document(indexName = "book_", shards = 5, replicas = 1)
@Data
public class BookIndexMapping {
    /**
     *  @Id标记数据主键
     */
    @Id
    private String id;

    /**
     * @Field标记字段。name:映射es中的字段;type:字段类型
     */
    @Field(name = "title_", type = FieldType.Keyword)
    private String title;

    @Field(name = "content_", type = FieldType.Text)
    private String content;

    @Field(name = "price_", type = FieldType.Double)
    private BigDecimal price;

    /**
     * 如果java类型使用java.util.Date,反序列化会失败
     */
    @Field(name = "publish_date_", type = FieldType.Date, format = DateFormat.date_hour_minute_second)
    private LocalDateTime publishDate;

}
